<template>
  <div class="dotation">
    <dv-scroll-board
      :config="Rotation"
      style="width: 100%; height: 100%"
      v-if="refresh"
      ref="scrollBoard"
    />
  </div>
</template>

<script>
export default {
  name: "Rotation",
  props: ["RecordIn", "RecordOut"],
  data() {
    return {
      refresh: true,
      Rotation: {
        data: [],
        columnWidth: [50],
      },
      page: 1,
    };
  },
  created() {
    this.getDistinguish(this.page, 15);
  },
  methods: {
    //获取车辆进出信息
    getDistinguish(page, count) {
      this.axios
        .get("/component/record", {
          params: {
            page: page,
            count: count,
          },
        })
        .then((res) => {
          if (res.data.code === "200") {
            const list = res.data.data.list;
            const len = list.length;
            let edata = [];
            list.forEach((item) => {
              let arr = [];
              for (let key in item) {
                if (item[key] !== null) {
                  arr.push(item[key]);
                }
              }
              edata.push(arr);
            });
            this.Rotation.data = edata;
            this.refresh = false;
            this.$nextTick(() => {
              this.refresh = true;
            });
          } else {
            this.$message.error(res.data.msg);
          }
        })
        .catch((err) => {
          console.error(err);
          this.$message.error("获取车辆进出列表失败");
        });
    },
  },
  watch: {
    RecordIn: {
      handler(newVal, oldVal) {
        const len = newVal.length;
        if (len !== 0) {
          let newArr = [];
          let arr = [];
          for (let key in newVal) {
            if (newVal[key] !== null) {
              arr.push(newVal[key]);
            }
          }
          newArr.push(arr);
          this.$refs["scrollBoard"].updateRows(newArr);
        }
      },
      deep: true,
    },
    RecordOut: {
      handler(newVal, oldVal) {
        const len = newVal.length;
        if (len !== 0) {
          let newArr = [];
          let arr = [];
          for (let key in newVal) {
            if (newVal[key] !== null) {
              arr.push(newVal[key]);
            }
          }
          newArr.push(arr);
          this.$refs["scrollBoard"].updateRows(newArr);
        }
      },
      deep: true,
    },
  },
};
</script>

<style scoped>
.dotation {
  margin-left: 2%;
  width: 95%;
  height: 80%;
}
</style>